package com.lemon.exam.controller;

import com.lemon.exam.common.annotation.Web;
import com.lemon.exam.common.web.Result;
import com.lemon.exam.entity.dto.PaperGradingDTO;
import com.lemon.exam.entity.vo.PaperGradingVO;
import com.lemon.exam.entity.vo.PaperStatisticsVO;
import com.lemon.exam.entity.vo.PaperVO;
import com.lemon.exam.service.IGradingPaperService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * 阅卷管理 控制器
 *
 * @author Lemon
 * @since 2025/5/17 11:20
 */
@RestController
@RequestMapping("gradingPaper")
@Tag(name = "阅卷管理", description = "阅卷管理 API")
@Web(childUri = "gradingPaper", childComponent = "system/GradingPaper.vue")
public class GradingPaperController {
    @Resource
    private IGradingPaperService gradingPaperService;

    /**
     * 查看所有试卷
     *
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("findPaperList")
    @Operation(summary = "查看所有试卷")
    public Flux<PaperVO> findPaperList(@RequestParam("type") String type, @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
        return gradingPaperService.findPaperList(type, pageNum, pageSize);
    }

    /**
     * 查询试卷
     *
     * @return
     */
    @GetMapping(value = "getGradingPaper/{paperId}")
    @Operation(summary = "查询试卷详情")
    public Mono<Map<String, Object>> getGradingPaper(@PathVariable("paperId") Long paperId) {
        return gradingPaperService.getGradingPaper(paperId);
    }

    /**
     * 阅卷
     *
     * @param paperId
     * @return
     */
    @GetMapping("grading")
    @Operation(summary = "阅卷")
    public Mono<Result<PaperGradingVO>> grading(@RequestParam("paperId") Long paperId, @RequestParam(value = "answerId", required = false) Long answerId) {
        return gradingPaperService.grading(paperId, answerId);
    }

    /**
     * 判分
     *
     * @param param
     * @return
     */
    @PostMapping("scoring")
    @Operation(summary = "判分")
    public Mono<String> scoring(@RequestBody PaperGradingDTO param) {
        return gradingPaperService.scoring(param);
    }

    /**
     * 试卷统计
     *
     * @param paperId
     * @return
     */
    @GetMapping("statistics/{paperId}")
    @Operation(summary = "阅卷结果统计")
    public Mono<PaperStatisticsVO> statistics(@PathVariable("paperId") Long paperId) {
        return gradingPaperService.statistics(paperId);
    }
}
